package com.practice.response;

import lombok.Data;

import java.util.List;

/**
 * @author kayn
 * @create 2023-10-09 上午 11:07
 */
@Data
public class ResponseL<T> {

    private Boolean success;
    private Integer code;
    private String message;
    private List<T> data;
    private long total;

    /**
     * 构造器
     * @param message 1
     * @param data 1
     * @param total 1
     * @return 1
     * @param <T> 1
     */
    public static <T> ResponseL<T> successWithMessage(String message, List<T> data, long total) {
        ResponseL<T> responseL = new ResponseL<>();
        responseL.success = true;
        responseL.code = 200;
        responseL.message = message;
        responseL.total = total;
        responseL.data = data;
        return responseL;
    }

    /**
     * 构造器
     * @param message 1
     * @return 1
     * @param <T> 1
     */
    public static <T> ResponseL<T> fail(String message) {
        ResponseL<T> responseL = new ResponseL<>();
        responseL.success = false;
        responseL.code = 500;
        responseL.message = message;
        responseL.total = 0;
        responseL.data = List.of();
        return responseL;
    }

}
